//教学流程
var TeachFlow03 = cc.Class.extend({
	step:0,
	flow:null,
	scene:null,
	tip:null,
	tip_frame:null,
	flash:null,
	//结束标志
	over_flag: false,
	curSprite:null,
	ctor: function(scene){
		this.scene=scene;
	},
	init: function(tip, tip_frame, flash){
		this.tip = tip;
		this.flash = flash;
		for(var i in gg.teachFlow){
			gg.teachFlow[i].finish = false;
			gg.teachFlow[i].id = i - -1;
			if(gg.teachFlow[i].action == null){
				gg.teachFlow[i].action = ACTION_NONE;				
			}
			if(gg.teachFlow[i].lock == null){
				gg.teachFlow[i].lock = true;
			}
		}
		this.tip_frame = tip_frame;
	},
	start:function(){
		this.over_flag = false;
		this.step = 0;
	},
	over:function(){
		this.over_flag = true;
		this.flow = over;
		this.scene.over();
	},
	checkTag:function(tag){
		var cur_flow = gg.teachFlow[this.step - 1];
		if(cur_flow.tag == tag){
			ll.tip_layer.arr.out();
			return true;
		} else {
			return false;
		}
	},
	prev:function(count){
		if(this.curSprite!=null){
			this.curSprite.stop();
			this.curSprite = null;
		}
		if(this.flow!=null){
			this.flow.cur = false;
		}
		this.step = this.step - count;
		this.flow = gg.teachFlow[this.step - 1];
		this.refresh();
	},
	//执行下一个任务
	next:function(){
		//流程结束
		if(this.over_flag){
			return;
		}
		if(this.curSprite!=null){
			this.curSprite.stop();
			this.curSprite = null;
		}
		if(this.flow!=null){
			this.flow.cur = false;
			// 标记任务已完成
			this.flow.finish = true;
		}
		this.flow = gg.teachFlow[this.step++];
		if(this.flow.finish){
			// 如果任务已完成，跳过当前步骤
			ll.tip_layer.arr.out();
			this.next();
		}
		this.refresh();
	},
	refresh:function(){
		// 刷新提示
		this.flow.cur = true;
		if(this.flow.tip != null){
			this.tip.doTip(this.flow.id + "." + this.flow.tip,gg.teachFlow);
		}
		if(this.flow.flash != null){
			this.flash.doFlash(this.flow.flash);
		}
		if(this.step > gg.teachFlow.length - 1){
			this.over();
		}
		this.initCurSprite();
		if(this.curSprite!=null){
//			this.curSprite.flash();	
			this.location();
			this.curSprite.setEnable(true);
		}
		var before = gg.teachFlow[this.step - 2];
		if(before == null || before.lock){
			synch_listener = true;
		}
	},
	location:/**
	 * 定位箭头
	 */
		function(){
		ll.tip_layer.arr.pos1(this.curSprite);		
	},
	getStep:function(){
		return this.step;
	},
	initCurSprite:function(){
		var tag = this.flow.tag;	
		var layer=this.scene.mainLayer;
		var arrayTag = 
			[TAG_ITEM_PAPERITEM,TAG_ITEM_PAPERITEM1,TAG_ITEM_DESK,
			 TAG_ITEM_COMPUTER_CLOSE,TAG_ITEM_COMPUTER_OPEN,TAG_ITEM_UV1800,
			 TAG_ITEM_EQUIT,TAG_ITEM_VESSEL1,TAG_ITEM_VESSEL2,
			 TAG_UV_OPENPC,TAG_UV_OPENUV,TAG_UV_EQUITMENT,
			 TAG_UV_EQUITMENT1,TAG_UV_SAMPLE
			 ];
		for(var i = 0; i < arrayTag.length; i++){
			var at = arrayTag[i];
			var sprite=null;
			var root=layer.getChildByTag(at);
			var sprite1=layer.getChildByTag(tag)
			if(root==null){
				continue;
			}else{
				if(root==sprite1){
					sprite=root;
				}else{
					sprite=root.getChildByTag(tag);
				}
			}
			if(sprite != null){
				if(this.flow.base != null && this.flow.base != at){
					continue;
				}
				this.curSprite = sprite;	
				return;
			}
		}
	}
});
